package indiwood.model.service;

import indiwood.model.PagingBean;
import indiwood.model.ProductionCommentVO;
import indiwood.model.ProductionListVO;
import indiwood.model.ProductionVO;
import indiwood.model.dao.ProductionDAO;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class ProductionServiceImpl implements ProductionService {
	@Resource(name = "productionDAOImpl")
	private ProductionDAO productionDAO;
	@Override
	public ProductionListVO productionList(String pageNo){
		if(pageNo==null||pageNo=="") 
		pageNo="1";
	List<ProductionVO> list=productionDAO.productionList(pageNo);
	int total=productionDAO.totalContent();
	PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
	ProductionListVO lvo=new ProductionListVO(list,paging);
	return lvo;
	}
	@Override
	public void write(ProductionVO pvo){
		productionDAO.write(pvo);
	}
	/*@Override
	public ProductionVO content(int no){
		productionDAO.updateCount(no);
		return productionDAO.content(no);
	}*/
	@Override
	public HashMap<String, Object> contentNoHit(int no){
		HashMap<String, Object> contentMap=new HashMap<String, Object>();
		ProductionVO pvo=productionDAO.content(no);
		contentMap.put("pvo", pvo);
		//ProductionCommentListVO pcvo=new ProductionCommentListVO();
		List<ProductionCommentVO> commentList=productionDAO.productionCommentList(pvo.getProductionNo());
		contentMap.put("commentList", commentList);
		/*int total=productionDAO.totalContent();
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		ProductionCommentListVO clvo=new ProductionCommentListVO(commentList, paging);
		contentMap.put("commentList", clvo);*/
		return contentMap;
	}
	@Override
	public void deleteBoard(String no){
		productionDAO.deleteBoard(no);
	}
	@Override
	public void updateBoard(ProductionVO pvo){
		productionDAO.updateBoard(pvo);
	}
	@Override
	public void commentWrite(ProductionCommentVO pcvo) {
		productionDAO.commentWrite(pcvo);
	}
/*	@Override
	public ProductionCommentListVO productionCommentList(String pageNo) {
		if(pageNo==null||pageNo=="") 
		pageNo="1";
	List<ProductionCommentVO> commentList=productionDAO.productionCommentList(pageNo);
	int total=productionDAO.totalContent();
	PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
	ProductionCommentListVO clvo=new ProductionCommentListVO(commentList, paging);
	
	return clvo;
	}*/
	@Override
	public HashMap<String, Object> content(int no){
		productionDAO.updateCount(no);
		HashMap<String, Object> contentMap=new HashMap<String, Object>();
		ProductionVO pvo=productionDAO.content(no);
		contentMap.put("pvo", pvo);
		//ProductionCommentListVO pcvo=new ProductionCommentListVO();
		List<ProductionCommentVO> commentList=productionDAO.productionCommentList(pvo.getProductionNo());
		contentMap.put("commentList", commentList);
		/*int total=productionDAO.totalContent();
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		ProductionCommentListVO clvo=new ProductionCommentListVO(commentList, paging);
		contentMap.put("commentList", clvo);*/
		return contentMap;
	}
	@Override
	public void deleteComment(String no) {
		productionDAO.deleteComment(no);
	}
}
